<template>
	<view class="content">
		<view class="box" v-for="element in formList">
			<view  v-for="item in fromFormatJson">
					<view class="box-con">
						<view class="box-con-left">{{ item.fieldTitle }}:</view>
						<view class="box-con-right">
							{{ element.dataJson[item.fieldName] }}
						</view>
				</view>
			</view>
			<view class="box-con">
				<view class="box-con-left">创建时间:</view>
				<view class="box-con-right">
					{{ element.createTime }}
				</view>
			</view>
		</view>
		<view class="" style="margin-top: 200rpx;" v-if="formList.length==0">
			<u-empty mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
import { searchPlugsFormById, searchPlugsFormDataList } from '@/utils/api.js';
export default {
	data() {
		return {
			formInfo: {},
			formId: [],
			fromFormatJson: [],
			formList: [],
			search: {
				page: 1,
				size: 10,
				total: 0
			}
		};
	},
	onLoad(option) {
		// uni.setNavigationBarTitle({
		// 	title: option.title
		// })
		this.formId = option.formId;
	},
	onShow() {
		this.getFormInfo();
	},
	onReachBottom() {
		if (this.formList.length < this.search.total) {
			this.search.page++;
			this.getFormList();
		}
	},
	methods: {
		getFormInfo() {
			let data = {
				id: this.formId
			};
			searchPlugsFormById(data).then((res) => {
				if (res.code == 200) {
					this.formInfo = res.body;
					this.fromFormatJson = JSON.parse(res.body.fromFormatJson);
					this.getFormList();
					uni.setNavigationBarTitle({
						title: this.formInfo.formName
					});
				}
			});
		},
		getFormList() {
			let data = {
				page: this.search.page,
				size: this.search.size,
				adminId: uni.getStorageSync('userInfo').id,
				userServiceToken: uni.getStorageSync('userInfo').userServiceToken,
				formId: this.formId
			};
			searchPlugsFormDataList(data).then((res) => {
				if (res.code == 200) {
					if (this.search.page == 1) {
						this.formList = [];
					}
					res.body.list.forEach((item) => {
					        item.dataJson = JSON.parse(item.dataJson)
					      })
					let arr = [];
					arr = this.formList.concat(res.body.list);
					this.formList = arr;
					
					this.search.total = res.body.total;
				}
			});
		}
	}
};
</script>

<style scoped lang="scss">
.content {
	padding: 20rpx;
	background-color: #f5f5f5;
	.box {
		background-color: #fff;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		padding:20rpx;
		.box-con {
			display: flex;
			align-items: center;
			padding: 10rpx 0;
			font-size: 28rpx;
			.box-con-left {
				color: #000;
				margin-right: 30rpx;
			}
			.box-con-right {
				color: #1d1e23;
			}
		}

		
	}
}
</style>
